package com.chenailin.www.daoimpl;

import com.chenailin.www.dao.AdministratorDAO;
import com.chenailin.www.pojo.Administrator;
import com.chenailin.www.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class AdministratorDAOImpl implements AdministratorDAO {

    // 修改密码
    @Override
    public boolean modifyPassword(Administrator administrator) throws SQLException {
        String sql = "UPDATE administrators SET password = ? WHERE id = ?";
        try (Connection conn = DBUtil.getConnection();
             PreparedStatement ps = conn.prepareStatement(sql)) {
            ps.setString(1, administrator.getPassword());
            ps.setInt(2, administrator.getAdminId());
            //受影响的行数
            int affectedRows = ps.executeUpdate();
            return affectedRows > 0;
        } catch (SQLException e) {
            System.err.println("数据库操作失败: " + e.getMessage());
            return false;
        }
    }
}
